import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Req, Query } from '@nestjs/common';
import { PermissionService } from './permission.service';
import { JwtGuard } from 'src/common/guards/jwt.guard';
import { ApiBearerAuth, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
import { Request } from 'express';
import { CreatePermissionDto } from './dto/permission.dto';

@ApiBearerAuth()
@UseGuards(JwtGuard)
@Controller('permission')
@ApiTags('权限模块')
export class PermissionController {
  constructor(private readonly permissionService: PermissionService) {}

  @Get('tree')
  @ApiOperation({ summary: '获取所有权限' })
  @ApiQuery({ name: 'name' })
  findAllPermission(@Req() req: Request) {
    return this.permissionService.findAllPermission(req);
  }

  @Get('getPermissionById')
  @ApiOperation({ summary: '根据id获取单一权限信息' })
  @ApiQuery({ name: 'id' })
  findPermissionById(@Query('id') id: number) {
    return this.permissionService.findPermissionById(id);
  }

  @Post('createPermission')
  @ApiOperation({ summary: '添加权限（菜单）' })
  createPermission(@Body() body: CreatePermissionDto) {
    return this.permissionService.createPermission(body);
  }
}
